using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;

namespace Pampa.WebControls
{
    public class SelectorResponse
    {
        private XmlDocument doc;
        private XmlNode nitems;

        public SelectorResponse(string valor, bool haymas)
        {
            doc = new System.Xml.XmlDocument();
            nitems = doc.CreateNode(XmlNodeType.Element, "items", "");
            doc.AppendChild(nitems);

            XmlAttribute avalue = doc.CreateAttribute("valor");
            avalue.Value = valor.ToUpper();
            nitems.Attributes.Append(avalue);

            XmlAttribute ahaymas = doc.CreateAttribute("haymas");
            ahaymas.Value = (haymas) ? "si" : "no";
            nitems.Attributes.Append(ahaymas);
        }

        public void AddItem(string id, string desc)
        {
            XmlNode nitem = doc.CreateNode(XmlNodeType.Element, "item", "");
            nitems.AppendChild(nitem);

            XmlNode nid = doc.CreateNode(XmlNodeType.Element, "id", "");
            nid.AppendChild(doc.CreateTextNode(id));

            XmlNode ndesc = doc.CreateNode(XmlNodeType.Element, "desc", "");
            ndesc.AppendChild(doc.CreateTextNode(desc));

            nitem.AppendChild(nid);
            nitem.AppendChild(ndesc);        
        }

        public XmlDocument Document
        {
            get 
            {
                return doc;
            }
        }
    }
}
